	<?php
	if (!empty($this->request->params['named']['name']) || !empty($this->request->params['named']['q']) || !empty($this->request->params['named']['city_slug']) || !empty($this->request->params['named']['category']) || (!empty($this->request->params['named']['filter']) && (empty($this->request->params['named']['view']) || (!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] != 'discover')))): 
		$grid_class = '';
	 else: 
		$grid_class = 'grid_18';
	endif;
	 if(!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] == 'discover') :
				$filter ='';
				if(!empty($this->request->params['named']['filter'])){
					switch ($this->request->params['named']['filter']){
						case 'recommended':
							$grid_class = 'grid_18';
						break;
						case 'popular':
								$grid_class = 'grid_18';
						break;
						case 'successful':
								$grid_class = 'grid_18';
						break;

					}
				}
		endif;				
		?>
<div class="<?php echo $grid_class; ?>  alpha">
<div class="js-response js-responses">
	<?php if (!empty($this->request->params['named']['name']) || !empty($this->request->params['named']['q']) || !empty($this->request->params['named']['city_slug']) || !empty($this->request->params['named']['category']) || (!empty($this->request->params['named']['filter']) && (empty($this->request->params['named']['view']) || (!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] != 'discover')))): ?>
	<div class="collections-side1 grid_6">
		<div class="l-curve-top">			
			<div class="r-curve-top">
				<div class="top-bg"> </div>
			</div>
		</div>
		<div class="shad-bg-lft clearfix">
			<div class="shad-bg-rgt">
				<div class="shad-bg">
					<?php echo $this->element('featured-links', array('config' => 'sec'));?>
					<?php echo $this->element('category-index', array('config' => 'sec'));?>
				</div>
			</div>
		</div>
		<div class="l-curve-bot">			
			<div class="r-curve-bot">
				<div class="bot-bg"> </div>
			</div>
		</div>
	</div>
	<div class="collections-side2 grid_18">
		<h3><?php echo $heading;?></h3>
	<?php endif; ?>
	<?php if(!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] == 'discover') : ?>
	<div>
		<h3><?php echo $discover_heading;?></h3>
	<?php endif; ?>
	<?php if (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'userview') : ?>
		   <div class="collections-side2">
	<?php endif; ?>

		<ol class="idea-list clearfix list project-list">
			<?php
				if (!empty($projects)):
					$i = 0;
					foreach ($projects as $project):
						$class = null;
						if ($i++ % 2 == 0) {
							$class = 'alpha';							
						}
						else{

							$class = 'altrow alpha';
						}
	  ?>
	  <li class="clearfix <?php echo $class; ?>">
					<div class="">
						<div class="l-curve-top">
							<div class="r-curve-top">
								<div class="top-bg"></div>
							</div>
						</div>
						<div class="shad-bg-lft clearfix">
							<div class="shad-bg-rgt">
								<div class="shad-bg">
										<div class="center clearfix">
											
									
													<div class="grid_2 list-content omega">
													<?php echo $this->Html->link($this->Html->showImage('Project', $project['Attachment'], array('dimension' => 'normal_medium_thumb', 'alt' => sprintf(__l('[Image: %s]'), $this->Html->cText($project['Project']['name'], false)), 'title' => $this->Html->cText($project['Project']['name'], false)),array('aspect_ratio'=>1)), array('controller' => 'projects', 'action' => 'view',  $project['Project']['slug'], 'admin' => false), array('escape' => false)); ?>
													</div>
													<div class="grid_11">
													<div class="project-head clearfix">
													<h3><?php echo $this->Html->link($this->Html->filterSuspiciousWords($this->Html->truncate($this->Html->cText($project['Project']['name'], false), 53), $project['Project']['detected_suspicious_words']),array('controller' => 'projects', 'action' => 'view',  $project['Project']['slug'], 'admin' => false), array('escape' => false, 'title' => $this->Html->filterSuspiciousWords($this->Html->truncate($this->Html->cText($project['Project']['name'], false), 53), $project['Project']['detected_suspicious_words'])));?></h3>
													<?php $collected_percentage = ($project['Project']['collected_percentage']) ? $project['Project']['collected_percentage'] : 0;?>
													</div>
													<div class="clearfix userplace">
                                                    <p class="grid_left"> <?php echo __l('by') . ' '; ?><?php echo $this->Html->link($this->Html->cText($project['User']['username']), array('controller' => 'users', 'action' => 'view', $project['User']['username']), array('escape' => false, 'title' => $this->Html->cText($project['User']['username'], false)));?></p>
														<p class="grid_left">
														<?php
															$location = array();
															$place = '';
															if (!empty($project['City'])) :
																if (isset($project['City']['name']) && !empty($project['City']['name'])) {
																	$location[] = $project['City']['name'];
																}
															endif;
															if (!empty($project['Country']['name'])) :
																$location[] = $project['Country']['name'];
															endif;
															$place = implode(', ', $location);
															if ($place):
																if(!empty($project['Country']['iso2'])):
														?>
															<span class="flags flag-<?php echo strtolower($project['Country']['iso2']); ?>" title ="<?php echo $project['Country']['name']; ?>"><?php echo $project['Country']['name']; ?></span>
														<?php
																endif;
																echo $this->Html->link($place, array('controller' => 'projects', 'action' => 'index', 'city'=>$project['City']['slug']), array('escape' => false));
															endif;
														?>
													</p>
                                                    </div>
          										<p class=""><?php echo $this->Html->filterSuspiciousWords($this->Html->truncate($this->Html->cText($project['Project']['short_description'], false), 200), $project['Project']['detected_suspicious_words']);?></p>
													
												<div class="progress-block clearfix">
														<p class="progress-bar" title = '<?php echo $this->Html->cFloat($collected_percentage,false).'%'; ?>'>
															<span style="width:<?php echo ($collected_percentage > 100) ? '100%' : $collected_percentage.'%'; ?>;" title = "<?php echo $this->Html->cFloat($collected_percentage,false).'%'; ?>"></span>
														</p>
													</div>
													<div class="clearfix">
             										<div class="clearfix">
														<dl class="deal-value grid_2">
															<?php if($project['Project']['project_status_id'] != ConstProjectStatus::Pending): ?>
																<dt><?php echo __l('funded') ?></dt>
																<dd><?php echo $this->Html->cInt($collected_percentage). __l('%');?></dd>
															<?php endif; ?>
														</dl>
														<dl class="deal-discount grid_2 alpha omega">
															<dt><?php echo __l('pledged') ?></dt>
															<dd><?php echo Configure::read('site.currency') . $this->Html->cCurrency($project['Project']['collected_amount']); ?></dd>
														</dl>
														<dl class="deal-save grid_2 alpha omega">

														<?php if (!empty($project['Project']['project_fund_goal_reached_date']) && $project['Project']['project_fund_goal_reached_date'] != '0000-00-00 00:00:00'): ?>
																<dt><?php echo __l('funded'); ?></dt>
																<dd><?php echo $this->Html->cDateTimeHighlight($project['Project']['project_fund_goal_reached_date']); ?></dd>
														<?php elseif($project['Project']['project_status_id'] == ConstProjectStatus::FundingExpired): ?>
																<dt><?php echo __l('expired'); ?></dt>
																<dd><?php echo $this->Html->cDateTimeHighlight($project['Project']['project_funding_end_date']); ?></dd>
														<?php elseif($project['Project']['project_status_id'] == ConstProjectStatus::ProjectCancelled): ?>
																<dt><?php echo __l('Cancelled'); ?></dt>
																<dd><?php echo $this->Html->cDateTimeHighlight($project['Project']['project_cancelled_date']); ?></dd>
														<?php else: ?>
																<dt><?php echo (round($project[0]['enddate']) >0) ? __l('days to go') : __l('hours to go'); ?></dt>
																<dd>
																	<?php
																		if ($project['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding || $project['Project']['project_status_id'] == ConstProjectStatus::ReserveAmountReached || $project['Project']['project_status_id'] == ConstProjectStatus::GoalReached):
																			if(round($project[0]['enddate']) >0):
																				echo $this->Html->cInt($project[0]['enddate']);
																			else:
																			$end_time = intval(strtotime($project['Project']['project_funding_end_date'] . ' 23:59:59') - time()); 			
																	?>
																				<div class="time-count">
																					<div class="js-countdown">&nbsp;</div>
																					<span class="js-time hide"><?php echo $this->Html->cInt($end_time,false);?></span>
																				</div>
																	<?php
																			endif;
																		endif;
																	?>
																</dd>
														<?php endif; ?>
													  </dl>
													</div>

													</div>
													</div>	
													<div class="grid_4 omega alpha">
												
													
											<?php if (Configure::read('Project.is_enable_idea')):
												$average_rating = (!empty($project['Project']['project_rating_count'])) ? ($project['Project']['total_ratings']/$project['Project']['project_rating_count']) : 0;
?>
														<div class="clearfix vote-count ">
														<ul class="votebg">
														<li>
														<span class="js-idea-vote-count-<?php echo $project['Project']['id']; ?> vote-count-value"><?php echo $this->Html->cInt($project['Project']['total_ratings']); ?></span> <?php echo __l('votes'); ?>
														</li>
														</ul>
													</div>
												<div class="vote-count-small clearfix">
													<ul class="list count-list clearfix">
														<li class="supporters" title="<?php echo __l('Supporters'); ?>"><?php echo $this->Html->cInt($project['Project']['project_rating_count']); ?></li>
														<li class="average" title="<?php echo __l('Average votes'); ?>"><?php echo $this->Html->cFloat($average_rating); ?></li>
													</ul>
												</div>
											<?php endif; ?>
													<dl class="feature-list">
													<?php if(!Configure::read('Project.is_fb_project_comment_enabled')): ?>
														<dt class="comments" title="<?php echo __l('Comments'); ?>"><?php echo __l('Comments:') . ' '; ?></dt>
															<dd><?php echo $this->Html->link($this->Html->cInt($project['Project']['project_comment_count']), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Comments'), array('escape' => false)); ?></dd>
														<?php endif; ?>
														<dt class="updates" title="<?php echo __l('Updates'); ?>"><?php echo __l('Updates:') . ' '; ?></dt>
															<dd><?php
															if(!empty($project['Project']['feed_url']) && Configure::read('Project.is_enable_rss_feed')){
																	echo $this->Html->link($this->Html->cInt($project['Project']['project_feed_count']), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Updates'), array('escape' => false));
															} else{
																echo $this->Html->link($this->Html->cInt($project['Project']['blog_count']), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Updates'), array('escape' => false));
															}


														?></dd>
														<dt class="views" title="<?php echo __l('Views'); ?>"><?php echo __l('Views:') . ' '; ?></dt>
														<dd><?php echo $this->Html->link($this->Html->cInt($project['Project']['project_view_count']), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug']), array('escape' => false)); ?></dd>
													</dl>
												</div>
									
								
											</div>
     	
								</div>
							</div>
						</div>
						<div class="l-curve-bot">
							<div class="r-curve-bot">
								<div class="bot-bg"></div>
							</div>
						</div>
					</div>
				</li>

			<?php
					endforeach;
				else:
			?>
				<li class="main-section">
				<p class="notice">
					<?php 
						if(!empty($this->request->params['named']['q'])):
							echo __l('Sorry, no results for ').'"'.$this->request->params['named']['q'].'".';
						else:
							 echo __l('No Projects available');
						endif;
						?>
					</p>
				</li>
			<?php
				endif;
			?>
		</ol>
		<?php if(!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] == 'discover') :
				$filter ='';
				if(!empty($this->request->params['named']['filter'])){
					switch ($this->request->params['named']['filter']){
						case 'recommended':
							$filter = __l('recommended');
						break;
						case 'popular':
							$filter =__l('popular');
						break;
						case 'successful':
							$filter =__l('successful');
						break;

					}
				}
		?>
			<p class="see-more-link"><?php echo $this->Html->link(__l('See more').' '.$filter.' '.__l('projects'), array('controller' => 'projects', 'action' => 'index', 'filter' => $this->request->params['named']['filter']), array('title' => $this->request->params['named']['filter'].' '.__l('projects')));?></p>
		<?php else: ?>

			<?php if (!empty($projects)) { ?>
				<?php echo $this->element('paging_links'); ?>
			<?php } ?>

		<?php endif; ?>
	<?php if(!empty($this->request->params['named']['view']) && $this->request->params['named']['view'] == 'discover') : ?>
	</div>
	<?php endif; ?>
	<?php if (!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'userview') : ?>
 </div>
	<?php endif;?>
</div>
</div>
